package DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.swing.JOptionPane;

import MODEL.Veiculos;

public class VeiculosDAO {

	public  boolean cadastrarVeiculo(Veiculos veiculo) throws SQLException {

		Connection conn = null;
		PreparedStatement stmt = null;
		Conexao com = new Conexao();
		boolean status=false;
		try {
			try {
				conn = com.getConnection();

			} catch (InstantiationException e) {

				e.printStackTrace();
			} catch (Throwable e) {
				e.printStackTrace();
			}

			stmt = conn.prepareStatement("INSERT INTO veiculos(Modelo,Chassi,Cor,Data_da_Compra,Disponibilidade,Placa,Tipo,observacoes) VALUE(?,?,?,?,?,?,?,?)");
			stmt.setString(1, veiculo.getCodigo());
			stmt.setString(2, veiculo.getChassi());
			stmt.setString(3, veiculo.getCor());
			stmt.setString(4, veiculo.getDatadacompra());
			stmt.setString(5, veiculo.getDisponibilidade());
			stmt.setString(6, veiculo.getPlaca());
			stmt.setString(7, veiculo.getTipo());
			stmt.setString(8, veiculo.getObservacoes());
			stmt.execute();
			status=true;

		} catch (SQLException e) {

			e.printStackTrace();

		} finally {
			if (conn != null)
				try {
					conn.close();
				} catch (SQLException e) {

					e.printStackTrace();
				}
			if (stmt != null)
				try {
					stmt.close();
				} catch (SQLException e) {

					e.printStackTrace();
				}
		}
		return status;
	}

}
